import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.ServerSocket;
import java.util.Vector;
import javax.swing.SwingUtilities;

public class ThreadConnectionHandler extends Thread {
    
    public Vector <HTTPHandler> handlers;
    public int port;
    public static ServerSocket server_socket;
    
    public ThreadConnectionHandler(int port) {
        this.port = port;
    }
    
    public void run() {
        MainWindow.window.addLogEntry("Thread Connection Handler started");
        
        this.handlers = new Vector<HTTPHandler>();
        try {
            ThreadConnectionHandler.server_socket = new ServerSocket(this.port);
            while (!ThreadConnectionHandler.server_socket.isClosed()) {
                HTTPHandler handler = new HTTPHandler(ThreadConnectionHandler.server_socket.accept());
                this.handlers.add(handler);
                handler.start();
            }
        } catch (IOException e) {
            System.err.println("ERROR: Problem launching HTTP handling thread.");
        }
        
        MainWindow.window.addLogEntry("Thread Connection Handler stopped");
    }
}
